<?php defined("MAIN_DIR") or die("No direct access");

$bank_id = trim(strip_tags($route->getPath(4)));
$bank_res = mysql_query("select `B`.`bank_id`,`B`.`full_name`,`C`.`path`,`C`.`city_id` from `bank` as `B`,`city` as `C` where `bank_id` = '$bank_id' and `C`.`city_id` = `B`.`city_id` limit 1");

if (mysql_num_rows($bank_res) == 0) {
	to("/$c_name/atms/");
}

$bank_row = mysql_fetch_array($bank_res);
if ($_SESSION['city'] != $bank_row['city_id']) {
	to("/$bank_row[path]/banks/atms/$bank_row[bank_id]");
}	

$atms_query = "select * from `atm` where `bank_id` = '$bank_id' order by `address`";

$limit = 20;
$atms_res = mysql_query($atms_query);
$count = mysql_num_rows($atms_res);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$atms_query .= " limit $start_list,$limit";
$atms_res = mysql_query($atms_query);
$atms_count = mysql_num_rows($atms_res);

$head_title = "Банкоматы ".$bank_row['full_name']." - «Банки России»";

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1><?php echo "Банкоматы ".$bank_row['full_name']; ?></h1>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td align="left" valign="top" class="banki_main_col">
			<div id="banki_table"><?php
				if ($count > 0)
				{
					$i = 0;
					?><table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr valign="middle">
							<td width="35" align="center" class="banki_table_item banki_table_number">№</td>
							<td width="250" align="center" class="banki_table_item banki_table_number">Адрес</td>
							<td width="200" align="center" class="banki_table_item banki_table_number">Объект</td>
							<td width="100" align="center" class="banki_table_item banki_table_number">Валюта</td>
							<td align="center" class="banki_table_item banki_table_number">Время работы</td>
						</tr><?php
					while ($atms_row = mysql_fetch_array($atms_res))
					{
						$i++;
						?><tr valign="middle" >
							<td align="center" class="banki_table_item banki_table_number"><?php
								echo $i+($page-1)*$limit;
							?></td>
							<td align="center" class="banki_table_item">
								<p><?php echo $atms_row['address'];?></p>
							</td>
							<td align="center" class="banki_table_item">
								<?php echo $atms_row['place']; ?>
							</td>
							<td align="center" class="banki_table_item">
								<?php echo $atms_row['currency']; ?>
							</td>
							<td align="center" class="banki_table_item">
								<?php echo $atms_row['work_time']; ?>
							</td>
						</tr><?php
					}
					?></table><?php
				}
				else
					echo "<h3 class='gag'>Не найдено банкоматов у данного банка</h3>";
			?></div>
			<div id="oprosy_table">
				<?php require_once APP."pageskin.php"; ?>
			</div>
		</td>
		<td width="159" align="left" valign="top"><?php
			require_once APP."rating_column.php";
			require_once APP."vacancy_column.php";
		?></td>
	</tr>
</table>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '1' limit 1"));
				$text = getRichText($info['text']);
				echo "<h2>$info[header]</h2>";
				echo "<p>$text</p>";
			?></td>
		</tr>
	</table>
</div>
<?php require_once APP.FOOTERFILE; ?>